package lxbAdmin;


import lxbAdmin.userSystem.entity.MenuInfo;
import lxbAdmin.userSystem.entity.SystemUserRole;
import lxbAdmin.userSystem.server.MenuService;
import lxbAdmin.userSystem.server.RoleService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class InitializerInfo {

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    public void init() {
        initMenu();
        initRole();
    }

    private void initRole() {
        List<SystemUserRole> systemUserRoles= roleService.findAll();
        if(systemUserRoles.size()< 1){
            SystemUserRole roleAdmin = new SystemUserRole();
            roleAdmin.setRoleName("超级管理员");
            roleService.addRole(roleAdmin);

            SystemUserRole roleAdmin1 = new SystemUserRole();
            roleAdmin1.setRoleName("普通管理员");
            roleService.addRole(roleAdmin1);

            SystemUserRole roleAdmin2 = new SystemUserRole();
            roleAdmin2.setRoleName("店员");
            roleService.addRole(roleAdmin2);

            SystemUserRole roleAdmin3 = new SystemUserRole();
            roleAdmin3.setRoleName("用户");
            roleService.addRole(roleAdmin3);
        }
    }

    private void initMenu() {
        List<MenuInfo> menuInfos= menuService.findAllMenu();
        if(menuInfos.size() < 1){
            MenuInfo userMenu=new MenuInfo();
            userMenu.setMenuName("用户管理");
            userMenu.setDelFlag("1");
            userMenu.setLink("/user");
            userMenu.setSort("1");
            menuService.addMenu(userMenu);

                MenuInfo ParentUserMenu= menuService.findByName("用户管理");

                MenuInfo userListMenu=new MenuInfo();
                userListMenu.setMenuName("用户列表");
                userListMenu.setDelFlag("1");
                userListMenu.setLink("/user/list");
                userListMenu.setSort("1");
                userListMenu.setParentMenuId(ParentUserMenu.getMenuId());
                menuService.addMenu(userListMenu);

                MenuInfo permissionMenu=new MenuInfo();
                permissionMenu.setMenuName("权限管理");
                permissionMenu.setDelFlag("1");
                permissionMenu.setLink("/user/permission");
                permissionMenu.setSort("2");
                permissionMenu.setParentMenuId(ParentUserMenu.getMenuId());
                menuService.addMenu(permissionMenu);

                MenuInfo roleMenu=new MenuInfo();
                roleMenu.setMenuName("角色分配");
                roleMenu.setDelFlag("1");
                roleMenu.setLink("/user/role");
                roleMenu.setSort("3");
                roleMenu.setParentMenuId(ParentUserMenu.getMenuId());
                menuService.addMenu(roleMenu);



            MenuInfo menuInfo=new MenuInfo();
            menuInfo.setMenuName("菜单管理");
            menuInfo.setDelFlag("1");
            menuInfo.setLink("/menu");
            menuInfo.setSort("1");
            menuInfo.setParentMenuId(menuInfo.getMenuId());
            menuService.addMenu(menuInfo);

                MenuInfo menugl= menuService.findByName("菜单管理");

                MenuInfo fl=new MenuInfo();
                fl.setMenuName("分类管理");
                fl.setDelFlag("1");
                fl.setLink("/menu/fl");
                fl.setSort("1");
                fl.setParentMenuId(menugl.getMenuId());
                menuService.addMenu(fl);

                MenuInfo splist=new MenuInfo();
                splist.setMenuName("商品列表");
                splist.setDelFlag("1");
                splist.setLink("/menu/splist");
                splist.setSort("2");
                splist.setParentMenuId(menugl.getMenuId());
                menuService.addMenu(splist);

                MenuInfo addsp=new MenuInfo();
                addsp.setMenuName("添加商品");
                addsp.setDelFlag("1");
                addsp.setLink("/menu/addsp");
                addsp.setSort("3");
                addsp.setParentMenuId(menugl.getMenuId());
                menuService.addMenu(addsp);

            MenuInfo orderMenu=new MenuInfo();
            orderMenu.setMenuName("订单管理");
            orderMenu.setDelFlag("1");
            orderMenu.setLink("/order");
            orderMenu.setSort("1");
            menuService.addMenu(orderMenu);

                MenuInfo dd= menuService.findByName("订单管理");

                MenuInfo ddlist=new MenuInfo();
                ddlist.setMenuName("订单列表");
                ddlist.setDelFlag("1");
                ddlist.setLink("/order/list");
                ddlist.setSort("1");
                ddlist.setParentMenuId(dd.getMenuId());
                menuService.addMenu(ddlist);

                MenuInfo updatedd=new MenuInfo();
                updatedd.setMenuName("修改订单");
                updatedd.setDelFlag("1");
                updatedd.setLink("/order/update");
                updatedd.setSort("2");
                updatedd.setParentMenuId(dd.getMenuId());
                menuService.addMenu(updatedd);

        }
    }


}
